var username = 'test';

window.onload=function () {
    function getRandomNumberByRange (start,end) {
        //username
        //return Math.round(Math.random() * (end - start) + start)
        var data = $.ajax({
            url:`/manage/api/public/identify/${start}/${end}`,
            dataType: 'json',
            async:false
        }).responseJSON;
        if (data.isSuccess){
            return Number(data.data.code);
        }
        return;
    };
    jigsaw.init(document.getElementById('captcha'),
        {
            getRandomNumberByRange:getRandomNumberByRange,
            getRandomImg: function (x) {
                return 'https://picsum.photos/300/150/?image=' + x
            },
            verifyRemote:function(left){
                //return Math.abs(left - this.x) < 10
                var data = $.ajax({
                    url:`/manage/api/public/identify/verify/${left}`,
                    dataType: 'json',
                    async:false
                }).responseJSON;
                return data.isSuccess;
            }
        },
        function () {
            document.getElementById('msg').innerHTML = '登录成功！'
        },
    )
}